package com.example.pinkcat.activity.changuserinfo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import com.example.pinkcat.R;
import com.example.pinkcat.activity.api.getData.GetData;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class birth extends AppCompatActivity {
    Context context=this;
    Spinner spinner;
    List<String> list = new ArrayList<String>();

    Spinner spinner1;
    List<String> list1 = new ArrayList<String>();

    Spinner spinner2;
    List<String> list2 = new ArrayList<String>();

    String year="1922";
    String month="01";
    String day="01";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Objects.requireNonNull(getSupportActionBar()).hide();//去掉标题栏
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
        setContentView(R.layout.activity_birth);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }//深色信息栏
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);//允许此线程内发起网络请求

        spinner=(Spinner) findViewById(R.id.nianSpanner);
        spinner1=(Spinner) findViewById(R.id.yueSpanner);
        spinner2=(Spinner) findViewById(R.id.riSpanner);

        setSpanner();
        listen();
    }
    void listen(){
        //返回键监听
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //确认修改键监听
        findViewById(R.id.change_enter).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (GetData.updateMsg(year+"-"+month+"-"+day,"birth",context))
                    onBackPressed();
            }
        });
        //下拉框选择监听
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                year=list.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                month=list1.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                day=list2.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }

    void setSpanner(){
        for (int i=1922;i<2030;i++){
            list.add(String.valueOf(i));
        }
        ArrayAdapter<String> spinner_adapter=new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,list);
        spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(spinner_adapter);


        for (int i=1;i<13;i++){
            if (i<10)
                list1.add("0"+String.valueOf(i));
            else
                list1.add(String.valueOf(i));
        }
        ArrayAdapter<String> spinner_adapter1=new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,list1);
        spinner_adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner1.setAdapter(spinner_adapter1);


        for (int i=1;i<32;i++){
            if (i<10)
                list2.add("0"+String.valueOf(i));
            else
                list2.add(String.valueOf(i));
        }
        ArrayAdapter<String> spinner_adapter2=new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,list2);
        spinner_adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner2.setAdapter(spinner_adapter2);
    }
}